export default class BaseModel {
	constructor(source,func) {
		this.data=[]
	    if (source) {
	    	if(this.isArrayFn(source)){
				source.map(item => {
					let object = this.objectfunc(item,func)
					this.data.push(object)
				})
	    	}else{
				if(Object.keys(source).length==0){
					this.data = source
				}else{
					let object = this.objectfunc(source,func)
					this.data = object
				}
	    	}
			this.superaddition()
	    } else {
			this.skeletonProcessor(func)
			// #ifdef TEST-WEIXIN
			this.emptyProcessor(func)
			// #endif
	    }
	}
	objectfunc(source,func){
		let objectsource = source
		if(func){
			objectsource = this.objecrelation(source,func)
		}
		return this.objectProcessor(objectsource,func)
	}
	objecrelation(source,func){
		
	}
	funcjudge(func){
		try{
			if(typeof func !== "function") {
				throw new Error("模型回调方法没有实现");
			}
		}catch(e){
			throw e;
		}
	}
	objectProcessor(source,func){
		
	}
	superaddition(){
		
	}
	skeletonProcessor(func){
		
	}
	emptyProcessor(func){
		
	}
	
	emptyViewData(){
		return null
	}
	
	checkURL(URL, address) {
		var str = URL;
		//判断URL地址的正则表达式为:http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
		//下面的代码中应用了转义字符"\"输出一个字符"/"
		var Base64 = /^\s*data:([a-z]+\/[a-z0-9-+.]+(;[a-z-]+=[a-z0-9-]+)?)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@\/?%\s]*?)\s*$/i;
		var Expression = /http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/;
		
		var objB64Exp = new RegExp(Base64);
		if(objB64Exp.test(str)==true){
			return URL || '';
		}
		var objExp = new RegExp(Expression);
		if (objExp.test(str) == true) {
			return URL || '';
		} else {
			return URL ? address + URL : ''
		}
	}
	
	isArrayFn(value) {
		if (typeof Array.isArray === "function") {
			return Array.isArray(value);
		} else {
			return Object.prototype.toString.call(value) === "[object Array]";
		}
	}
}